package com.cuckoo.mall.thus.menuaccount.favorite;

import android.support.annotation.Nullable;
import android.text.Html;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;

import com.bgn.baseframe.utils.BaseStringUtil;
import com.bgn.baseframe.utils.UiUtil;
import com.bgn.baseframe.utils.imageloader.ImageLoader;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.cuckoo.mall.R;
import com.cuckoo.mall.javabean.Product;
import com.cuckoo.mall.thus.menucart.CartQiuckAdapter;

import java.util.List;

/**
 * Created by Administrator on 2018/3/30.
 */

public class FavoriteListAdapter extends BaseQuickAdapter<Product, BaseViewHolder> {
    private boolean isEditMode = false;

    private CartQiuckAdapter.ItemCheckChange callBack;

    public FavoriteListAdapter(@Nullable List<Product> data, CartQiuckAdapter.ItemCheckChange itemCheckChange) {
        super(R.layout.list_item_favorite, data);

        callBack = itemCheckChange;
    }

    public void setEditMode(boolean mode) {
        isEditMode = mode;
        notifyDataSetChanged();
    }

    @Override
    protected void convert(final BaseViewHolder helper, final Product itemData) {
        if (isEditMode) {

            helper.setGone(R.id.check_edit, true);
           // helper.setGone(R.id.tv_add_cart, false);
        } else {
            helper.setGone(R.id.check_edit, false);
          //  helper.setGone(R.id.tv_add_cart, true);
        }
        //helper.addOnClickListener(R.id.tv_add_cart);
        final CheckBox checkBox = helper.getView(R.id.check_edit);
        checkBox.setChecked(itemData.isSelected());
        ((CheckBox) helper.getView(R.id.check_edit)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                itemData.setSelected(checkBox.isChecked());
                if (callBack != null) callBack.whenItemCheckChangeCllBack();
            }
        });
        helper.setText(R.id.tv_name, itemData.getName());
        helper.setText(R.id.tv_price, itemData.getCurrency()+" " + BaseStringUtil.getPrioceFormatString(itemData.getPrice()));
        if (itemData.getMarket_price() != 0) {
            helper.setText(R.id.tv_max_price, BaseStringUtil.addDeleteLineToText(itemData.getCurrency() + " " + BaseStringUtil.getPrioceFormatString(itemData.getMarket_price())));
            //helper.setText(R.id.tv_max_price, Html.fromHtml("<strike>" + itemData.getCurrency()+" " + BaseStringUtil.getPrioceFormatString(itemData.getMarket_price()) + "</strike>"));
        } else {
            helper.setText(R.id.tv_max_price, "");
        }

        ImageLoader.load(itemData.getImage()).into((ImageView) helper.getView(R.id.iv_image));

        if (helper.getAdapterPosition() == getItemCount() - 1) {
            helper.setGone(R.id.view_line, false);
        } else {
            helper.setGone(R.id.view_line, true);
        }

    }
}
